package org.krams.tutorial.service;

import org.apache.log4j.Logger;
import org.krams.tutorial.client.MoneyDTO;
import org.krams.tutorial.service.dao.MoneyDao;
import org.krams.tutorial.service.model.Money;

import java.util.ArrayList;
import java.util.List;

public class SpringService {
    private MoneyDao moneyDao;

    public MoneyDao getMoneyDao() {
        return moneyDao;
    }

    public void setMoneyDao(MoneyDao moneyDao) {
        this.moneyDao = moneyDao;
    }

    protected static Logger logger = Logger.getLogger("service");
	
	public String echo(String msg) {
		logger.debug("Entering SpringService");
		
		return "Hello " + msg + " from Spring!";
	}

    public List<MoneyDTO> loadAllMoneys(){
        List<Money> moneys = moneyDao.findAll();
        List<MoneyDTO> moneyDTOs = new ArrayList<MoneyDTO>(moneys.size());
        for(Money money : moneys){
            moneyDTOs.add(new MoneyDTO(money.getDate(),money.getAmount()));
        }
        return moneyDTOs;
    }

    public double getBalance(){
        return moneyDao.getBalance();
    }

}
